CoAP Package : CoAP package interfaces
The CoapPackage
class describes the CoAP
protocol format and provides operation interfaces for protocol settings. Both the client and server can access CoAP
data through this type of object.
Support
The following shows CoapPackage
module APIs available for each permissions.
User Mode | Privilege Mode | |
---|---|---|
package.remote | ● | ● |
package.token | ● | ● |
package.options | ● | ● |
package.payload | ● | ● |
package.code | ● | ● |
package.path | ● | ● |
package.method | ● | ● |
package.setOption | ● | ● |
package.appendOption | ● | ● |
package.setOptions | ● | ● |
package.getOption | ● | ● |
package.setPayload | ● | ● |
package.appendPayload | ● | ● |
package.isConfirm | ● | ● |
Package Object
package.remote
- {Object} Server socket address.
package.token
- {Buffer} Message token, Identify resources requested.
package.options
- {Object} Coap options. See APIs:
package.setOption
package.appendOption
package.setOptions
package.getOption
package.payload
- {String | Buffer} Coap payload to be send or received.
package.code
{String} Code request method code for request and response status code for response. Details:
Code Description 2.01
Created. 2.02
Deleted. 2.03
Valid. 2.04
Changed. 2.05
Content. 4.00
Bad Request. 4.01
Unauthorized. 4.02
Bad Option. 4.03
Forbidden. 4.04
Not Found. 4.05
Method Not Allowed. 4.06
Not Acceptable. 4.12
Precondition Failed. 4.13
Request Entity Too Large. 4.15
Unsupported Content-Format. 5.00
Internal Server Error. 5.01
Not Implemented. 5.02
Bad Gateway. 5.03
Service Unavailable. 5.04
Gateway Timeout. 5.05
Proxying Not Supported.
package.path
- {Stiring} Coap Uri-Path.
package.method
- {String} Coap request method. Coap support method:
GET
POST
PUT
DELETE
package.setOption(key[, val])
key
{String} Option name.val
* {Any | Undefined}* Option value. If val equalundefined
, this option will be removed.
Set or remove package option. The coap option details:
No. | Name | Format | Length | Default |
---|---|---|---|---|
1 | If-Match | opaque | 0-8 | (none) |
3 | Uri-Host | string | 1-255 | (#) |
4 | ETag | opaque | 1-8 | (none) |
5 | If-None-Match | empty | 0 | (none) |
7 | Uri-Port | uint | 0-2 | (#) |
8 | Location-Path | string | 0-255 | (none) |
11 | Uri-Path | string | 0-255 | (none) |
12 | Content-Format | uint | 0-2 | (none) |
14 | Max-Age | uint | 0-4 | 60 |
15 | Uri-Query | string | 0-255 | (none) |
17 | Accept | uint | 0-2 | (none) |
20 | Location-Query | string | 0-255 | (none) |
35 | Proxy-Uri | string | 1-1034 | (none) |
39 | Proxy-Scheme | string | 1-255 | (none) |
60 | Sizel | uint | 0-4 | (none) |
package.appendOption(key, val)
key
{String} Option name.val
* {Any | Array}* Option value.
Add or append package option.
package.setOptions(opts)
opts
{Object} Coap options,
Set multiple options.
package.getOption(key)
key
{String} Option name.- Returns: {Undefined | Array | Any} Option value.
Get option value.
package.setPayload([chunk])
chunk
{Undefined | String | Buffer | Object} Payload data. If chunk undefined, payload set to undefined.
Set package payload.
package.appendPayload(chunk)
chunk
{String | Buffer | Object} Payload data.- Returns: {Boolean} Append payload success or not.
Set or append package payload. This api can be call multiple times.
package.isConfirm()
- Returns: {Boolean} The request is confirm or no.
Confirm(CON
): A request that needs to be acknowledged. If a CON
request is sent, the other party must respond. This request is used for reliable transmission.
No confirm(NON
): There is no need to confirm the request, if the NON
request is sent, then the other party does not have to respond. This request is unreliable.